/*******************************************************************************
 * Copyright 2008 www.softao.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
/**
 * Place holder for copyright, needs to be replaced before release.
 */
package com.softao.ming.gwt.drawing2d.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImpl;

/**
 * 
 */
public class Graphics {
	private final Element mElement;
	private final GraphicsImpl mImpl = GWT.create(GraphicsImpl.class);
	
	/**
	 * Initializes a new instance of <code>Graphics</code>.
	 * 
	 * @param element
	 *            the element where to paint the graphics
	 */
	public Graphics(final Element element) {
		if (element == null) {
			String msg = "element can not be null reference.";
			throw new NullPointerException(msg);
		}

		this.mElement = element;
		this.mImpl.initialize(this.mElement);
	}
	
	/**
	 * @return the element
	 */
	public final Element getElement() {
		return mElement;
	}
	
	/**
	 * @param value the fill style
	 */
	public void setFillStyle(final String value) {
		this.mImpl.setFillStyle(value);
	}
	
	/**
	 * @param value the stroke style
	 */
	public void setStrokeStyle(final String value) {
		this.mImpl.setStrokeStyle(value);
	}
	
	/**
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 */
	public void strokeRect(float x, float y, float width, float height) {
		this.mImpl.strokeRect(x, y, width, height);
	}
	
	/**
	 * Fills the specified rectangle.
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 */
	public void fillRect(float x, float y, float width, float height) {
		this.mImpl.fillRect(x, y, width, height);
	}

	/**
	 * Begins the path construction.
	 */
	public void beginPath() {
		this.mImpl.beginPath();
	}
	
	/**
	 * @param value
	 */
	public void setLineWidth(float value) {
		this.mImpl.setLineWidth(value);
	}
	
	/**
	 * @param x
	 * @param y
	 */
	public void moveTo(float x, float y) {
		this.mImpl.moveTo(x, y);
	}
	
	/**
	 * @param x
	 * @param y
	 */
	public void lineTo(float x, float y) {
		this.mImpl.lineTo(x, y);
	}
	
	/**
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 */
	public void rect(float x, float y, float w, float h) {
		this.mImpl.rect(x, y, w, h);
	}
	
	/**
	 * @param x
	 * @param y
	 * @param radius
	 * @param startAngle
	 * @param endAngle
	 * @param anticlockwise
	 */
	public void arc(float x, float y, float radius, float startAngle,
			float endAngle, boolean anticlockwise) {
		this.mImpl.arc(x, y, radius, startAngle, endAngle, anticlockwise);
	}
	
	/**
	 * 
	 */
	public void closePath() {
		this.mImpl.closePath();
	}
	
	/**
	 * 
	 */
	public void stroke() {
		this.mImpl.stroke();
	}
	
	/**
	 * @param cpx
	 * @param cpy
	 * @param x
	 * @param y
	 */
	public void quadraticCurveTo(float cpx, float cpy, float x, float y) {
		this.mImpl.quadraticCurveTo(cpx, cpy, x, y);
	}
	
	/**
	 * @param cp1x
	 * @param cp1y
	 * @param cp2x
	 * @param cp2y
	 * @param x
	 * @param y
	 */
	public void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) {
		this.mImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
	}
	
	/**
	 * 
	 */
	public void fill() {
		this.mImpl.fill();
	}
	
	/**
	 * @param x
	 * @param y
	 */
	public void translate(float x, float y) {
		this.mImpl.translate(x, y);
	}
	
	/**
	 * Saves the status of the graphics.
	 */
	public void save() {
		this.mImpl.save();
	}
	
	/**
	 * @param value
	 */
	public void setGlobalAlpha(float value) {
		this.mImpl.setGlobalAlpha(value);
	}
	
	/**
	 * 
	 */
	public void restore() {
		this.mImpl.restore();
	}
	
	/**
	 * @param angle
	 */
	public void rotate(float angle) {
		this.mImpl.rotate(angle);
	}
}
